package com.chen.spring.cloud.service.coupon.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chen.entity.Coupon;
import com.chen.vo.MyCouponVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 优惠券 Mapper 接口
 * </p>
 *
 * @author 陈永鹏
 * @since 2019-03-26
 */
public interface CouponMapper extends BaseMapper<Coupon> {

    @Select("        SELECT\n" +
            "            a.code_id,\n" +
            "            a.`code`,\n" +
            "            a.u_id,\n" +
            "            a.is_used,\n" +
            "            a.add_time,\n" +
            "            a.start_time,\n" +
            "            a.end_time,\n" +
            "            a.is_delete,\n" +
            "            b.coupon_id,\n" +
            "            b.face_value,\n" +
            "            b.`name`,\n" +
            "            b.description,\n" +
            "            b.`status`\n" +
            "        FROM\n" +
            "            zs_coupon_code a,\n" +
            "            zs_coupon b\n" +
            "        WHERE a.coupon_id = b.coupon_id\n" +
            "        AND b.`status` = 0\n" +
            "        AND a.is_delete = 0\n" +
            "        AND a.u_id = #{u_id}\n" +
            "        Order by a.end_time desc\n" +
            "        limit #{start},#{end}")
    List<MyCouponVo> myCoupons (Map<String,Integer> parms);


    @Select("SELECT\n" +
            "            count(1)\n" +
            "        FROM\n" +
            "            zs_coupon_code a,\n" +
            "            zs_coupon b WHERE a.coupon_id = b.coupon_id\n" +
            "        AND b.`status` = 0\n" +
            "        AND a.is_delete = 0\n" +
            "        AND a.u_id = #{u_id}")
    Integer getMyCouponCount (@Param(value = "u_id") int u_id);

}
